package caiziyou.com.designpattern.commond;

public class RemoateController {

	// 开按钮的命令数组
	private Commond[] onCommonds;
	private Commond[] offCommonds;

	// 撤销命令
	private Commond undoCommond;

	public RemoateController() {
		onCommonds = new Commond[5];
		offCommonds = new Commond[5];
		for (int i = 0; i < 5; i++) {
			onCommonds[i] = new NoCommand();
			offCommonds[i] = new NoCommand();
		}
	}

	public void setCommond(int no, Commond commond, Commond offCommond) {
		onCommonds[no] = commond;
		offCommonds[no] = offCommond;
	}

	public void onButtonPushed(int no) {

		onCommonds[no].execute();

		undoCommond = onCommonds[no];
	}

	public void offButtonPushed(int no) {

		offCommonds[no].execute();

		undoCommond = offCommonds[no];
	}

	public void undoButtonPush() {
		undoCommond.undo();
	}
}
